//
//  ViewController.swift
//  DrawBarChart
//
//  Created by xiong on 2024/11/18.
//

import UIKit
import SnapKit
class ViewController: UIViewController {

    var dataArr:[Float] = []
    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.backgroundColor = .white
        
        view.addSubview(chartView)
//        chartView.snp.makeConstraints { make in
//            make.edges.equalToSuperview()
//        }
        
        
        dataArr = [0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]
        
       
        chartView.spectra = [dataArr]
        let timer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(timer(time:)), userInfo: nil, repeats: true)

    }
    
    @objc func timer(time:Timer) {
        dataArr.append(Float.random(in: 0.01..<1))
        dataArr.removeFirst()
        let data = [dataArr]
        print("\(data)")
        chartView.spectra = data
    }
    
    
    lazy var chartView: SpectraView = {
        let view = SpectraView(frame: CGRect(x: 0, y: CGRectGetHeight(self.view.frame)-200, width: CGRectGetWidth(self.view.frame), height: 200))
        return view
    }()
}

